function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {

    $(".focused").click(function () {
        // TODO 取消关注当前新闻作者
        var user_id = $(this).attr("data-userid");
        var action = 'unfollow';
        var params = {
            "user_id": user_id,
            "action": action
        };
        $.ajax({
            url: "/news/followed_user",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            headers: {"X-CSRFToken": getCookie("csrf_token")},
            success: function (resp) {
                if (resp.errno=="0"){
                    window.location.reload();
                }else{
                    alert(resp.errmsg);
                }
            }
        })
    })
});